package ch.nostromo.tiffanys.engines;

import java.util.logging.Logger;

import uk.ac.cam.cl.projectcharlie2010.engines.Engine;

public class EngineTimer extends Thread {
  static Logger logger = Logger.getLogger(EngineTimer.class.getName());

  private double seconds;
  private Engine engine;

  private boolean running;

  public void stopRunnning() {
    this.engine = null;
    this.running = false;
  }

  public EngineTimer(Engine engine, double seconds) {
    this.seconds = seconds;
    this.engine = engine;
  }

  @Override
  public void run() {
    try {
      this.running = true;
      long ms = (long) (seconds * 1000);
      Thread.sleep(ms);
    } catch (InterruptedException ignored) {
      // ignore
    }
    
    if (running && engine != null) {
      engine.setRunning(false);
    }
  }
}
